﻿#coding=utf-8

from constant import const
from config import Cfg

class PermitManager(object):
    #_limit_permission = {const.P_EXPORT:False,
    #                    const.PERMIT_MODIFY_ORDER:False,
    #                    const.PERMIT_DEL_ORDER:False}
    
    _limit_permission = [False] * const.PERMIT_CNT 
    
    @classmethod
    def load(cls):  
        cls._limit_permission[const.PERMIT_MODIFY_ORDER_TEMP] = True
        
    
    @classmethod
    def accessTest(cls, permision, user=None, refuseHit=True):
        if user is None:
            user = Cfg.getCurUser()
        
        if user.isLimited():
            allow = cls._limit_permission[permision]
        else:    
            allow = True
    
        if (not allow and refuseHit):
            cls.showRefuse()
        
        return allow
            
    @classmethod
    def showRefuse(cls, parent=None):
        import wx
        msg = u'访问受限：您的账号没有访问权限'
        dlg = wx.MessageDialog(parent, msg,u'提示',wx.OK|wx.ICON_INFORMATION)
        dlg.ShowModal()
        
    